﻿@using E5_KhuyenMaiVang.Models;
@model IEnumerable<E5_KhuyenMaiVang.Models.VOUCHER>

@{
    ViewBag.Title = "VoucherManager";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<DEAL> deals = ViewBag.Deals;
    var Statuses = ViewBag.Statuses;
    var VoucherStatuses = ViewBag.VoucherStatuses;
    double TongTien = 0;
    int i = 0;
}
@foreach (var item in Model)
      {
          TongTien += item.Price;
      }
<div id="random_deal">
	<div class="title-content"> </div>

    <form method="post" action="@Url.Action("SearchVoucher","Company")">


	<table width="100%" border="0">
	  <tr>
	    <td colspan="4"><div class="title-content">QUẢN LÝ VOUCHER KHUYẾN MÃI</div></td>
        <td width="0%"></td>        
        </tr>
        <tr>
	    <td width="17%">
        <small>Khuyến mãi:</small>        	
        </td>
        <td width="16%">
            <select size="1" id="select" name="DealID">
                <option value="0">Tất cả</option>
        		@foreach (var item in deals)
                {
                    <option value="@item.DealID">@item.DealName</option>
                }
        	</select> 
        </td>
            <td width="12%"><input class="submit-form" name="submit" value="Tìm" type="submit" /></td>
            <td width="55%"><small><i>Tìm kiếm theo Khuyến mãi,Tình trạng,Tên khách hàng và mã voucher. Để trống nếu bạn muốn bỏ qua.</i></small></td>
	    </tr>
	  <tr>
	    <td width="17%">
        <small>Tình trạng:</small>        	
        </td>
        <td width="16%">
            <select size="1" id="select" name="StatusID">
        		<option value="0">Tất cả</option>
                @foreach (var item in Statuses)
                {
                    <option value="@item.StatusID">@item.StatusName</option>
                }
        	</select> 
        </td>
            <td width="12%"></td>
            <td width="55%"></td>
	    </tr>
         <tr>         
	    <td width="17%">
        <br/>
        <small>Tên khách hàng:</small>
        </td>
        <td><input type="text" name="MemberName" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
	    </tr>
        <tr>         
	    <td width="17%">
        <br/>
        <small>Mã voucher:</small>
        </td>
        <td><input type="text" name="VoucherID" /></td>
        <td></td>
        <td width="55%"><b><small>Tổng số voucher: </small><small style="color:Green">@Model.Count()</small></b>
    <br />
    <b><small>Tổng số tiền: </small><small style="color:Red">@TongTien</small></b></td>
	    </tr>
	  <tr>
	    <td><br/><small>Trang:</small> : <a href="#" style="text-decoration:none ; color:#333; font-weight:bold ;">1</a> <a href="#" style="text-decoration:none ; color:#333; font-weight:bold ; ">2</a></td>
	    </tr>
	  </table>

      </form>

      <br/>
      
	<table width="850" style="border:1px #333 solid ; border-collapse:collapse; border-spacing: 0px;">
	  <tr> 
        <td width="5%" align="center" class="namecolumn" scope="col">STT</td>
        <td width="15%" align="center" class="namecolumn" scope="col">Khuyến mãi</td>
	    <td width="5%" align="center" class="namecolumn" scope="col">Mã voucher</td>
         <td width="15%"align="center" class="namecolumn" scope="col">Người mua</td>  
           <td width="15%"align="center" class="namecolumn" scope="col">Số điện thoại</td>  
             <td width="15%"align="center" class="namecolumn" scope="col">Địa chỉ</td>         
	    <td width="15%"align="center" class="namecolumn" scope="col">Ngày mua</td>
	    <td width="15%"align="center" class="namecolumn" scope="col">Tình trạng </td>
      </tr>

      @foreach (var item in Model)
      {
          TongTien += item.Price ;
          <tr  style="border-bottom:2px #666 solid;">
            <td align="center" class="rowcolumn">@(++i)</td>
            <td align="center" class="rowcolumn">@item.DEAL.DealName</td>
	        <td align="center" class="rowcolumn">@item.VoucherID</td>
	        <td align="center" class="rowcolumn">@item.MEMBER.MemberName</td>
            <td align="center" class="rowcolumn">@item.MEMBER.Phone</td>
            <td align="center" class="rowcolumn">@item.MEMBER.Address</td>
	        <td align="center" class="rowcolumn">@item.PurchaseDate</td>
            <form method="post" action="@Url.Action("UpdateStatus","Company")">
	        <td align="center" class="rowcolumn">
                <select size="1" id="select" name="VoucherStatus" onchange="this.form.submit()">
        		    @foreach (var sitem in VoucherStatuses)
                    {
                        int sitemStatus = sitem.StatusID;
                        int currentStatus = item.StatusID;
                        if (sitemStatus != currentStatus)
                        {
                        <option value="@sitem.StatusID">@sitem.StatusName</option>
                        }
                        else { 
                            <option value="@sitem.StatusID" selected="true" >@sitem.StatusName</option>
                        }
                    }
        	    </select>
                <input type="hidden" name="VoucherID" value="@item.VoucherID" />
            </td>
            </form>
          </tr>	 
      }
	  

            
     </table>
  </div>
  
  <table width="100%">
</table>